package cn.huaguo.trigger.job;

import cn.huaguo.domain.task.repository.ITaskRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Description 定时任务
 * @Author wangQian
 * @Date 2024/5/17
 */
@Slf4j
@Component
public class UpdateTaskStockJob {
    @Resource
    private ITaskRepository taskRepository;

    @Scheduled(cron = "0/5 * * * * ?")
    public void exec() {
        try {
            //log.info("定时任务：更新任务库存");
            String id = taskRepository.takeQueueValue();
            if (id == null) {
                //log.info("库存队列为空，跳过更新");
                return;
            }
            taskRepository.updateTaskStock(id);
            log.info("更新任务库存成功");
        } catch (Exception e) {
            log.error("更新任务库存失败 {}", e.getMessage());
        }
    }
}
